package org.stratusdb.funsql.compile.operator;

import java.io.Serializable;
import java.util.HashMap;

import org.stratusdb.metadata.Connection;


public abstract class AbstractOperator implements Serializable {

	private static final long serialVersionUID = -5531022011681321483L;

	//attributes
	protected Result result;
	protected EnumOperator type;
	protected Connection connFlag = null;
	protected HashMap<String,Integer> cols = new HashMap<String,Integer>();
	
	//getters and setters
	public Result getResult() {
		return result;
	}

	public void setResult(Result result) {
		this.result = result;
	}

	public EnumOperator getType() {
		return type;
	}

	public void setType(EnumOperator type) {
		this.type = type;
	}
	
	public void setConnection(Connection connFlag) {
		this.connFlag = connFlag;
	}
	
	public Connection getConnection() {
		return this.connFlag;
	}
	
	public void addColumn(String colname, int colid) {
		this.cols.put(colname, colid);
	}
	
	@SuppressWarnings("unchecked")
	public void setColumns(HashMap<String,Integer> tmp) {
		this.cols = (HashMap<String,Integer>) tmp.clone();
	}
	
	@SuppressWarnings("unchecked")
	public HashMap<String,Integer> getColumns(){
		return (HashMap<String,Integer>) this.cols.clone();
	}
	
	public int getColumn(String s) {
		return this.cols.get(s);
	}
	
	public String toString() {
		return ((this.getConnection()==null)?"null":this.getConnection().getUrl()) +" : "
				+ this.getType() +" : " + this.getColumns().size() + " : " + this.getColumns();
	}
}
